//app.js
import { getCache, setCache } from './utils/util'
App({
  onShow(e) {
    
  },
  onLaunch: function (e) {
    this.globalData.sceneid = e.scene
    this.globalData.isLogin = getCache('isLogin');
    this.globalData.userInfo = getCache('userInfo');
    this.globalData.x_tk = getCache('x_tk');

    const device = wx.getSystemInfoSync()
    this.globalData.safeArea = device.platform.includes('andr') ? 0 : (device.screenHeight - device.safeArea.bottom - (device.screenTop ? device.screenTop : 0))
    
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        // console.log('showShareMenu',res);
      }
    })

    var updateManager = wx.getUpdateManager();
    updateManager.onCheckForUpdate(function (res) {
      if (res.hasUpdate) {
        wx.showToast({
          title: "即将有更新请留意"
        });
      }
    });
    
    updateManager.onUpdateReady(() => {
      wx.showModal({
        title: "更新提示",
        content: "新版本已经准备好，是否立即使用？",
        success: function(res) {
          if (res.confirm) {
            // 调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate();
          } else {
            wx.showToast({
              icon: "none",
              title: "小程序下一次「冷启动」时会使用新版本"
            });
          }
        }
      });
    });
  },
  globalData: {
    safeArea: 0,

    //domain: 'http://localhost:8080/wxapi/',
    domain: 'https://nh.it-cn.cn/wxapi/',
    isLogin: false,
    userInfo: '',
    x_tk: '',
    isReload: false,
    pageData: '',
    // print
    canWrite: false, // 是否可以打印标志
    deviceId: '',
    serviceId: '',
    characteristicId: '',
    // print end
  }
})
// {
//   "pagePath": "pages/index/index",
//   "iconPath": "images/maing.png",
//   "selectedIconPath": "images/main.png",
//   "text": "首页"
// },
// {
//   "pagePath": "pages/mine/setting/index",
//   "iconPath": "images/twitterg.png",
//   "selectedIconPath": "images/twitter.png",
//   "text": "圈子"
// },